package com.bigchui.DesignPattern.proxy.jdkproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * Created by wangzhen on 2019/3/10.
 */
public class JDKMeipo implements InvocationHandler {
    private Object target;
    public JDKMeipo(Object target){
        this.target=target;
    }

    public Object getInstance(){
        return Proxy.newProxyInstance(target.getClass().getClassLoader(),target.getClass().getInterfaces(),this);
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("before增强");
        Object returnValue = method.invoke(target, args);
        System.out.println("after增强");
        return returnValue;
    }
}
